package com.leetcode.problems077;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode-cn.com/problems/combinations/
 * @Date 2021/12/09 14:34
 * @Author ghery
 * @Version V1.0
 */
public class Solution {

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> ans = new ArrayList<>();
        combine(n,1,k,new ArrayList<>(),ans);
        return ans;
    }


    public void combine(int n, int i, int k,List<Integer> res,List<List<Integer>> ans) {
        if(k == 0){
            ans.add(new ArrayList<>(res));
            return;
        }
        for (; i + k - 1<= n; i++) {
            res.add(i);
            combine(n,i + 1,k - 1,res,ans);
            res.remove(res.size() - 1);
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution().combine(4,2));
    }
}
